package com.toolbox.controller.infra;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.toolbox.annotation.OperateLog;
import com.toolbox.base.BaseController;
import com.toolbox.dto.InfraMenuDTO;
import com.toolbox.req.InfraMenuReq;
import com.toolbox.result.ResponseResultDTO;
import com.toolbox.service.InfraMenuService;
import com.toolbox.validation.group.CreateAction;
import com.toolbox.validation.group.UpdateAction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜单权限 前端控制器
 * </p>
 *
 * @author Mango
 * @since 2023-12-01
 */
@SuppressWarnings("ALL")
@ApiSort(100)
@Api(tags = "菜单权限 前端控制器")
@RestController
@RequestMapping("/menu-do")
public class InfraMenuController extends BaseController {

    @Autowired
    private InfraMenuService service;

    /**
     * 获取——菜单权限列表
     *
     * @return 集合
     */
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "获取——菜单权限列表")
    @GetMapping(value = "/get-menu-nodes")
    public ResponseResultDTO<List<InfraMenuDTO>> getMenuNodes() {
        return ResponseResultDTO.success(service.getMenuNodes());
    }

    /**
     * 创建——菜单权限
     *
     * @param req 参数
     * @param bo  当前操作人
     * @return 主键ID
     */
    @OperateLog(operateName = "创建——菜单权限", operateItem = "infra_menu")
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "创建——菜单权限")
    @PostMapping(value = "/create-menu")
    public ResponseResultDTO<Long> createMenu(@RequestBody @Validated(CreateAction.class) InfraMenuReq req) {
        return ResponseResultDTO.success(service.createMenu(req, init()));
    }

    /**
     * 更新——菜单权限
     *
     * @param req 参数
     * @param bo  当前操作人
     * @return 主键ID
     */
    @OperateLog(operateName = "更新——菜单权限", operateItem = "infra_menu")
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "更新——菜单权限")
    @PutMapping(value = "/update-menu-by-id")
    public ResponseResultDTO<Long> updateMenuById(@RequestBody @Validated(UpdateAction.class) InfraMenuReq req) {
        return ResponseResultDTO.success(service.updateMenuById(req, init()));
    }

    /**
     * 删除——菜单权限
     *
     * @param id 主键ID
     */
    @OperateLog(operateName = "更新——菜单权限", operateItem = "infra_menu")
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "删除——菜单权限")
    @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", dataTypeClass = Long.class, paramType = "query", example = "1", required = true)
    @DeleteMapping(value = "/remove-by-id")
    public ResponseResultDTO<Void> removeById(@RequestParam(name = "id") Long id) {
        service.removeById(id);
        return ResponseResultDTO.success();
    }

}
